package com.jdk17feature;

import java.util.Arrays;
import java.util.List;

/**
 * @author piaohailin@163.com
 * @date 2021/9/17
 */
public class RecordTest {
    public static void main(String... args) {
        Student s1 = new Student(1, "Shazin", 1);
        Student s2 = new Student(2, "Shahim", 2);
        System.out.println("Student 1 : " + s1);
        System.out.println("Student 2 : " + s2);
        System.out.println("s1 == s2 : " + (s1 == s2));
        System.out.println("s1.equals(s1) : " + (s1.equals(s1)));
        System.out.println("s1.equals(s2) : " + (s1.equals(s2)));
        record GraduateStudent(Student student, List<String> qualifications) {
        }
        ;
        GraduateStudent gs1 = new GraduateStudent(s1, Arrays.asList("A/S", "BSc"));
        System.out.println("GraduateStudent 1 : " + gs1);
    }

    private static record Student(Integer id, String name, Integer grade) {
        public Student {  // All args constructor
            if (grade < 0 || grade > 13) {
                throw new IllegalArgumentException("Grade must be between 1 and 13");
            }
        }
    }
}